<html>
<head><meta charset="utf-8"><title>mir inline cost · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html">mir inline cost</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190114908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190114908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> andjo403 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190114908">(Mar 09 2020 at 20:34)</a>:</h4>
<p>what is the cost that is calculated for mir inlining? While looking in to why the instance_def_size_estimate function estimate do not match the number of llvm-ir instructions there was alot of code that only is generated in llvm so I guess my question is if that shall be handled in the mir inline cost?<br>
e.g. mir calls/drops that have a cleanup generate one extra BB (landingpad) that contains 10 llvm-ir instructions and also mir resume results in 9 llvm-ir instructions</p>



<a name="190115431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190115431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190115431">(Mar 09 2020 at 20:40)</a>:</h4>
<p>The cost calculation is here <a href="https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L215" target="_blank" title="https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L215">https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L215</a></p>



<a name="190115503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190115503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190115503">(Mar 09 2020 at 20:41)</a>:</h4>
<p>It's done at the MIR statement level so there's definitely a disconnect between that and what LLVM sees.</p>



<a name="190115690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190115690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> andjo403 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190115690">(Mar 09 2020 at 20:43)</a>:</h4>
<p>my thinking is that maybe at eg line <a href="https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L331" target="_blank" title="https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L331">https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L331</a> to increase the cost with 10 due to the landingpad BB</p>



<a name="190115786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190115786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190115786">(Mar 09 2020 at 20:44)</a>:</h4>
<p>You mean add another 10 for calls that can unwind?</p>



<a name="190116132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190116132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> andjo403 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190116132">(Mar 09 2020 at 20:48)</a>:</h4>
<p>yes so eg. for mir <code>_2 = const std::vec::Vec::&lt;T&gt;::as_mut_ptr(move _3) -&gt; [return: bb2, unwind: bb15];</code><br>
the extra bb cleanup bb is before bb15 in llvm ir <br>
<code> cleanup:                                          ; preds = %bb12, %bb11, %bb10, %bb8, %bb4, %bb5, %bb2, %start
  %27 = landingpad { i8*, i32 }
          cleanup
  %28 = bitcast { i8*, i32 }* %2 to i8*
  call void @llvm.lifetime.start.p0i8(i64 16, i8* %28)
  %29 = extractvalue { i8*, i32 } %27, 0
  %30 = extractvalue { i8*, i32 } %27, 1
  %31 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %2, i32 0, i32 0
  store i8* %29, i8** %31, align 8
  %32 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %2, i32 0, i32 1
  store i32 %30, i32* %32, align 8
  br label %bb15</code></p>



<a name="190117032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190117032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190117032">(Mar 09 2020 at 20:59)</a>:</h4>
<p>That's a good idea!</p>



<a name="190118411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190118411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> andjo403 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190118411">(Mar 09 2020 at 21:14)</a>:</h4>
<p>call and assert also  have a cleanup variable that also generate a landingpad</p>



<a name="190383227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190383227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190383227">(Mar 12 2020 at 12:27)</a>:</h4>
<p>I think inline costs at the MIR level are more pseudo than science</p>



<a name="190385812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/mir%20inline%20cost/near/190385812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/mir.20inline.20cost.html#190385812">(Mar 12 2020 at 12:56)</a>:</h4>
<p>but I don't have the time to relitigate that so let's pretend I didn't say anything :P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>